package cn.pomelo.signal.common;

import cn.pomelo.signal.config.SignalConfig;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Util {

    public static List<File> readTxt() throws IOException {
        File file = new File(SignalConfig.getData());
        File[] files = file.listFiles((f) -> {
            return f.getName().endsWith(".txt");
        });
        return Arrays.asList(Objects.requireNonNull(files));
    }


    public static <T> List<List<T>> splitList(List<T> list, Long dataSize, int offset) {
        return Stream.iterate(0, i -> {
                    return i + 1;
                }).limit((int) Math.ceil((double) dataSize / offset)).parallel().map(
                        n -> {
                            return list.stream().skip((long) n * offset).limit(offset).parallel().collect(Collectors.toList());
                        })
                .collect(Collectors.toList());
    }
}
